package edu.towson.greenteam.tab;

import java.util.ArrayList;

import edu.towson.greenteam.Iterator;
import edu.towson.greenteam.order.Order;
import edu.towson.greenteam.offer.*;

public class Tab {
	private int pinID;
	private ArrayList<Order> orderArrayList;
	private float discount;
	private boolean paid;

	public Tab(int id) {
		this.pinID = id;
		this.paid = false;
		this.discount = 0;
		this.orderArrayList = new ArrayList<Order>();
	}

	public Tab getTab() {
		return this;
	}

	public int getId() {
		return pinID;
	}

	public void applyBestDiscount(Offers offers) {
		float tempDiscount = 0;
		
		Iterator<Offer> offerIterator = offers.getItr();
		//offerIterator.next();
		while(offerIterator.hasNext())
		{
			Offer currentOffer = offerIterator.next();
			if (currentOffer.getMinTabValue() <= getTotal())
			{
				if (tempDiscount <= currentOffer.getOfferAmt())
				{
					tempDiscount = currentOffer.getOfferAmt();
				}
			}
		}
		this.discount = tempDiscount;
	}

	public float getTotal() {
		float totalPrice = 0;

		for (Object o : orderArrayList.toArray()) {
			Order order = (Order)o;
			totalPrice += order.getPrice();
		}

		return totalPrice;
	}

	public void setPaymentstatus(boolean paymentStatus) {
		this.paid = paymentStatus;
	}

	public boolean isPaid() {
		return this.paid;
	}
	
	public float getDiscount() {
		return this.discount;
	}
	
	public boolean addMenuItem(Order order)
	{
		orderArrayList.add(order);
		return true;
	}
}
